<?php

abstract class Kzend_Bootstrap_Abstract extends Zend_Application_Bootstrap_Bootstrap
{
    public function __construct($application)
    {
        parent::__construct($application);

        require_once 'Zend/Loader/Autoloader.php';
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->unregisterNamespace(array(
                'Zend_',
                'ZendX_'))->setFallbackAutoloader(true);

        Zend_Controller_Action_HelperBroker::addPrefix("Kzend_Controller_Helper");
    }

    protected function _initView()
    {
	
        $view = new Revulo_View_Phtmlc();
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $viewRenderer->setView($view);
		
        $configs = $this->getOptions();
        $view->setCompilePath($configs['kzend']['viewCompilePath']);
		
        $view->setHelperPath("Kzend/View/Helper", "Kzend_View_Helper");
		
    }

    protected function _initDatabase()
    {
        $dbh = Kzend_DbManager::getInstance();

        $config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/database.ini", APPLICATION_ENV);

        $dbh->initDatabase($config->database->adapter, $config->database->params->toArray());
    }

    protected function _initConfig()
    {
        $configs = $this->getOptions();

        Zend_Registry::set("appConfig", $configs);
    }

    protected function _initLogger()
    {
        $logger = null;

        try {
            $this->bootstrap("log");
            $logger = $this->getResource("log");
            if ($logger === null) {
                $logger = new Zend_Log(new Zend_Log_Writer_Null());
            }
        } catch (Exception $e) {
            $logger = new Zend_Log(new Zend_Log_Writer_Null());
        }

        Zend_Registry::set("Kzend_Logger", $logger);
    }

    protected function _initMessageManager()
    {
        $this->bootstrap("message");
        $messageManager = $this->getResource("message");

        Zend_Registry::set("Kzend_MessageManager", $messageManager);
    }
}

